package com.efast.dmom.mes.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.PieceWage;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.PieceWageService;

@Controller
@RequestMapping("/pieceWage")
public class PieceWageController {
	
	@Autowired
	private PieceWageService pieceWageService;
	
	@RequestMapping(value = "/deletePieceWage")
	public @ResponseBody ResultBean deletePieceWage(@RequestBody PieceWage pieceWage) {
		return pieceWageService.deletePieceWage(pieceWage);
	}
	
	@RequestMapping(value = "/operateByPieceWage")
	public @ResponseBody ResultBean operateByPieceWage(@RequestBody PieceWage pieceWage) {
		ResultBean resultBean = new ResultBean(true, ' ');
		// Judge to add
		if (pieceWage.getModificationFlag() == IModificationFlags.NEW) {
			return pieceWageService.save(pieceWage);
	    // Judge to update
		} else if (pieceWage.getModificationFlag() == IModificationFlags.MODIFIED) {
			return pieceWageService.update(pieceWage);
		} 
		return resultBean;
	}

}
